<%@page import="com.friends.library.Dto.Login"%>
<%@page import="java.util.Iterator"%>
<%@page import="org.hibernate.Transaction"%>
<%@page import="com.friends.library.persistence.HibernateUtil"%>
<%@page import="org.hibernate.SessionFactory"%>
<%@page import="org.hibernate.*"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
String username=request.getParameter("username");
String password=request.getParameter("password");
Session session2=HibernateUtil.getSessionFactory().openSession();
Transaction transaction=session2.beginTransaction();
String sql="from Login where username=:username";
Query query=session2.createQuery(sql);
query.setString("username",username);
Iterator iterator=query.iterate();
while(iterator.hasNext()){
	Login login=(Login)iterator.next();
	String user=login.getUsername();
	String pass=login.getPassword();
	if(user.equalsIgnoreCase(username)&&pass.equals(password)){
		session.setAttribute("username",username);
		
		%>
		<jsp:forward page="index.jsp"/>
		<% 
	}else{
		%>
		<h2 style="color: red">Username and Password Didn't Match</h2>
		<jsp:include page="login.jsp"></jsp:include>
		<% 
	}
}
%>

</body>
</html>